﻿using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Awesome.Extensions.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Awesome.Extensions.QualityTools
{
    public static class AssertEx
    {
        /// <summary>
        /// Assert.IsTrue
        /// </summary>
        [DebuggerStepThrough]
        public static void AssertTrue(this bool result)
        {
            Assert.IsTrue(result);
        }

        /// <summary>
        /// Assert.IsFalse
        /// </summary>
        [DebuggerStepThrough]
        public static void AssertFalse(this bool result)
        {
            Assert.IsFalse(result);
        }

        /// <summary>
        /// Assert.AreEqual
        /// </summary>
        [DebuggerStepThrough]
        public static void AssertEquals<T>(this T value, T eq)
        {
            Assert.AreEqual<T>(value, eq);
        }

        /// <summary>
        /// Assert.AreNotEqual
        /// </summary>
        [DebuggerStepThrough]
        public static void AssertNotEquals<T>(this T value, T eq)
        {
            Assert.AreNotEqual<T>(value, eq);
        }

        [DebuggerStepThrough]
        public static void AssertSequenceEqual<T>(this IEnumerable<T> source, IEnumerable<T> other)
        {
            source.SequenceEqual(other).AssertTrue();
        }

        [DebuggerStepThrough]
        public static void AssertSequenceEqual<T>(this IEnumerable<T> source, params T[] other)
        {
            source.SequenceEqual(other).AssertTrue();
        }

        private static void  AssertSetEqualInternal<T>(this IEnumerable<T> source, IEnumerable<T> other)
        {
            //TODO: is it right way?

            (source.Except(other).IsEmpty() && other.Except(source).IsEmpty()).AssertTrue();
        }

        [DebuggerStepThrough]
        public static void AssertSetEqual<T>(this IEnumerable<T> source, IEnumerable<T> other)
        {
            source.AssertSetEqualInternal(other);
        }

        [DebuggerStepThrough]
        public static void AssertSetEqual<T>(this IEnumerable<T> source, params T[] other)
        {
            source.AssertSetEqualInternal(other);
        }

    }
}
